package com.deploy.demo.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import org.springframework.core.env.Environment;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 测试控制器 - 用于验证系统功能
 */
@Slf4j
@RestController
@RequestMapping("/test")
@RequiredArgsConstructor
@Tag(name = "系统测试", description = "用于测试系统功能的接口")
public class TestController {

    private final Environment environment;

    /**
     * 健康检查
     */
    @GetMapping("/health")
    @Operation(summary = "健康检查", description = "检查系统健康状态")
    public ResponseEntity<Map<String, Object>> health() {
        Map<String, Object> response = new HashMap<>();
        response.put("code", 0);
        response.put("message", "系统运行正常");
        response.put("data", "healthy");

        return ResponseEntity.ok(response);
    }

    /**
     * 获取当前环境信息
     */
    @GetMapping("/env")
    @Operation(summary = "获取环境信息", description = "获取当前应用的环境信息")
    public ResponseEntity<Map<String, Object>> getEnvironmentInfo() {
        Map<String, Object> response = new HashMap<>();
        response.put("code", 0);
        response.put("message", "环境信息获取成功");

        Map<String, Object> data = new HashMap<>();
        data.put("applicationName", environment.getProperty("spring.application.name"));
        data.put("version", environment.getProperty("app.version"));
        data.put("description", environment.getProperty("app.description"));
        data.put("activeProfiles", environment.getActiveProfiles());
        data.put("port", environment.getProperty("server.port"));
        data.put("env", environment.getProperty("app.env"));

        response.put("data", data);

        return ResponseEntity.ok(response);
    }

}